package asteroids.expression;

import asteroids.model.programs.*;

public abstract class BooleanOperator extends BooleanExpression {
	Expression arg1;
	Expression arg2;
	private Expression initialArg1;
	private Expression initialArg2;

	public BooleanOperator(Expression expression1, Expression expression2) {
		if (!(expression1 instanceof Expression)
				|| !(expression2 instanceof Expression)) {
			initialArg1 = new BooleanExpression();
			initialArg2 = new BooleanExpression();
		} else {
			initialArg1 = expression1;
			initialArg2 = expression2;
		}
	}

	public BooleanOperator(Expression expression) {
		this(expression, null);
	}

	public void updateArguments(Program program) {
		Expression temparg1 = initialArg1;
		Expression temparg2 = initialArg2;
		if (!(initialArg1 instanceof BooleanExpression)) {
			if (initialArg1 instanceof Variable
					&& ((Variable) initialArg1).getRef(program) instanceof BooleanExpression) {
				temparg1 = ((Variable) initialArg1).getRef(program);
			} else {
				temparg1 = new BooleanExpression();
			}
		}
		if (!(initialArg2 instanceof BooleanExpression)) {
			if (initialArg2 instanceof Variable
					&& ((Variable) initialArg2).getRef(program) instanceof BooleanExpression) {
				temparg2 = ((Variable) initialArg2).getRef(program);
			} else {
				temparg2 = new BooleanExpression();
			}
		}
		this.arg1=temparg1;
		this.arg2=temparg2;

	}

}